(function (vc) {

    vc.extends({
        propTypes: {
            callBackListener: vc.propTypes.string, //父组件名称
            callBackFunction: vc.propTypes.string //父组件监听方法
        },
        data: {
            addIntegralShopRuleInfo: {
                ruleId: '',
                ruleName: '',
                money: '',
                amount: '',

            }
        },
        _initMethod: function () {

        },
        _initEvent: function () {
            vc.on('addIntegralShopRule', 'openAddIntegralShopRuleModal', function () {
                $('#addIntegralShopRuleModel').modal('show');
            });
        },
        methods: {
            addIntegralShopRuleValidate() {
                return vc.validate.validate({
                    addIntegralShopRuleInfo: $that.addIntegralShopRuleInfo
                }, {
                    'addIntegralShopRuleInfo.ruleName': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "规则名称不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "128",
                            errInfo: "规则名称不能超过128"
                        },
                    ],
                    'addIntegralShopRuleInfo.money': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "金额不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "30",
                            errInfo: "金额不能超过30"
                        },
                    ],
                    'addIntegralShopRuleInfo.amount': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "积分数不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "30",
                            errInfo: "积分数不能超过30"
                        },
                    ],
                });
            },
            saveIntegralShopRuleInfo: function () {
                if (!$that.addIntegralShopRuleValidate()) {
                    vc.toast(vc.validate.errInfo);
                    return;
                }

                $that.addIntegralShopRuleInfo.shopId = vc.getCurrentCommunity().shopId;

                vc.http.apiPost(
                    '/integralShopRule.saveIntegralShopRule',
                    JSON.stringify($that.addIntegralShopRuleInfo),
                    {
                        emulateJSON: true
                    },
                    function (json, res) {
                        //vm.menus = vm.refreshMenuActive(JSON.parse(json),0);
                        let _json = JSON.parse(json);
                        if (_json.code == 0) {
                            //关闭model
                            $('#addIntegralShopRuleModel').modal('hide');
                            $that.clearAddIntegralShopRuleInfo();
                            vc.emit('integralShopRule', 'listIntegralShopRule', {});

                            return;
                        }
                        vc.toast(_json.msg);

                    },
                    function (errInfo, error) {
                        console.log('请求失败处理');

                        vc.toast(errInfo);

                    });
            },
            clearAddIntegralShopRuleInfo: function () {
                $that.addIntegralShopRuleInfo = {
                    ruleName: '',
                    money: '',
                    amount: '',

                };
            }
        }
    });

})(window.vc);
